package com.eedi.framework.errorcode.framework.error;

import com.eedi.framework.errorcode.ErrorCodeAutoGenerateReq;
import com.eedi.framework.errorcode.controller.sys.vo.SysErrorCodeAutoGenerateReq;
import com.eedi.framework.errorcode.core.generator.ErrorCodeAutoGenerator;
import com.eedi.framework.errorcode.service.SysErrorCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class ErrorCodeAutoGeneratorImpl  implements ErrorCodeAutoGenerator {
    @Resource
    SysErrorCodeService sysErrorCodeService;

    @Override
    public void execute(List<ErrorCodeAutoGenerateReq> errorCodeAuto) {
        List<SysErrorCodeAutoGenerateReq> reqs=new ArrayList<>();
        SysErrorCodeAutoGenerateReq req;
        for (ErrorCodeAutoGenerateReq e:errorCodeAuto){
            req=new SysErrorCodeAutoGenerateReq();
            req.setSysErrorCodeAppName(e.getApplicationName())
                    .setSysErrorCode(e.getCode())
                    .setSysErrorMessage(e.getMessage());
            reqs.add(req);
        }
        sysErrorCodeService.autoGenerateErrorCodes(reqs);
    }
}
